﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace VFCons
{
	public partial class FTLightOperations : UserControl
	{
		public EventHandler Buttons_Clicked = null;
		public FTLightOperations()
		{
			InitializeComponent();
			buttonLightA.Tag = 0;
			buttonLightB.Tag = 1;
			buttonSetA.Tag = 2;
			buttonSetB.Tag = 3;

			buttonLightA.Click += Buttons_Click;
			buttonLightB.Click += Buttons_Click;
			buttonSetA.Click += Buttons_Click;
			buttonSetB.Click += Buttons_Click;

			BrightnessA = 100;
			BrightnessB = 100;
			ALighting = false;
			BLighting = false;
		}

		private void Buttons_Click(object sender, EventArgs e)
		{
			Button btn = sender as Button;
			string txt = "请注意有效数值 ";
			try
			{
				int tag = Convert.ToInt32(btn.Tag);
				if (tag == 2)
				{
					txt += labelScopeA.Text;
					ba = Convert.ToUInt16(textBoxLightA.Text);
				}
				else if (tag == 3)
				{
					txt += labelScopeB.Text;
					bb = Convert.ToUInt16(textBoxLightB.Text);
				}

			}
			catch (Exception ex)
			{
				MessageBox.Show(txt + Environment.NewLine + ex.Message, "ERROR");
				return;
			}
			if (Buttons_Clicked != null) Buttons_Clicked(sender, e);
		}

		public string LabelA
		{
			get { return labelScopeA.Text; }
			set { labelScopeA.Text = value;Invalidate(); }
		}
		public string LabelB
		{
			get { return labelScopeB.Text; }
			set { labelScopeB.Text = value; Invalidate(); }
		}

		private ushort ba = 0;
		public ushort BrightnessA
		{
			get { return ba; }
			set { ba = value;textBoxLightA.Text = ba.ToString();Invalidate(); }
		}
		private ushort bb = 0;
		public ushort BrightnessB
		{
			get { return bb; }
			set { bb = value; textBoxLightB.Text = bb.ToString(); Invalidate(); }
		}

		private bool _Alighting = false;
		public bool ALighting
		{
			get { return _Alighting; }
			set { _Alighting = value; buttonLightA.BackColor = value ? Color.Green : SystemColors.Control; }
		}
		private bool _Blighting = false;
		public bool BLighting
		{
			get { return _Blighting; }
			set { _Blighting = value; buttonLightB.BackColor = value ? Color.Green : SystemColors.Control; }
		}
	}
}
